package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.com.example.myapplication.User;

public class MainActivity extends AppCompatActivity {

    private Button log;
    private Button reg;
    private EditText i_user;
    private EditText i_password;
    private TextView tips;
    private boolean is_tips;
    public User user;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化
        installControl();

        log.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String login_U = i_user.getText().toString();
                String login_p = i_password.getText().toString();
                if(login_U.equals("")||login_p.equals("")){
                    Toast.makeText(MainActivity.this,"不能为空",Toast.LENGTH_SHORT).show();
                }else if(login_U.equals("yqytestcount")&&login_p.equals("12345678")||login_U.equals("zhoujiahao")&&login_p.equals("12345678")||login_U.equals("houruibiao")&&login_p.equals("12345678")){
                    tips.setText("登录成功");
                    tips.setTextColor(Color.RED);
                    is_tips = true;
                }
                else{
                    Toast.makeText(MainActivity.this,"登录失败",Toast.LENGTH_SHORT).show();
                }
            }
        });
        reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(is_tips == true){
                    Jump_page();
                }else{
                    Toast.makeText(MainActivity.this,"请先登录",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    public void installControl(){
        i_user = (EditText) findViewById(R.id.put_u);
        i_password = (EditText)findViewById(R.id.put_p);
        log = (Button)findViewById(R.id.login);
        reg = (Button)findViewById(R.id.register);
        tips = findViewById(R.id.tips);
        is_tips = false;
        //设置竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setTitle("登录");
    }
    public void Jump_page(){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,RequestLayout.class);
        MainActivity.this.startActivity(intent);
    }
}